<template>
    <div>
        <Modal width="800"
               v-model="modal.updateModal"
               @on-ok="ok"
               @on-cancel="cancel"
               draggable
               scrollable
               :loading="loading"
               title="课程类型更新">
            <Form :label-width="90">
                <FormItem label="类型级别:">
                    <RadioGroup v-model="modal.courseType.courseTypeTag">
                        <Radio disabled label="1">一级类型</Radio>
                        <Radio disabled label="2">二级类型</Radio>
                    </RadioGroup>
                </FormItem>
                <FormItem label="类型名称">
                    <Input v-model="modal.courseType.courseTypeName"/>
                </FormItem>
                <FormItem v-if="modal.courseType.courseTypeTag==2" label="类型名称">
                    <Select v-model="modal.courseType.parentId">
                        <Option v-for="index in parentIdList" :key="index.courseTypeId" :value="index.courseTypeId">{{index.courseTypeName}}</Option>
                    </Select>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                parentIdList:[],
                loading:true
            }
        },
        watch:{

        },
        props:{
            modal:{
                updateModal:false,//模态框的关闭状态
                courseType:{}//点击编辑传过来的对象
            }
        },
        methods:{
            ok(){
                this.http.post("/courseType/editCourseType",this.qs.stringify(this.modal.courseType)).then(res=>{
                    if(res.code===200&&res.data==true){
                        this.$Message.success("操作成功！！！")
                        this.$emit("updatestatus",true)
                    }else {
                        this.$Message.error("保存出错啦！！！")
                        this.$emit("updatestatus",false)
                    }
                } )
            },
            /**
             * 点击了关闭
             */
            cancel(){
                this.$emit("updatestatus",false)
            },
        /**
         *
         * @param text
         */
            isInputNull(text){
                this.$Message.warning(text);
                setTimeout(() => {
                this.loading = false;
                this.$nextTick(() => {
                    this.loading = true;
                })
                }, 500);
            },
            getParent(){
                this.http.get("/courseType/getParentAndChildren").then(res => {
                    if (res.data) {
                        this.parentIdList = res.data.parentList;
                    }
                })
            }
        },
        watch:{
            /**
             *利用'modal.addModal'变量值为true的情况下在里面进行初始化，防止父组件加载时候子组件也同时加载
             * @param val
             */
            'modal.updateModal'(val){
                if(val){
                    this.getParent();
                }
            }
        }
    }
</script>

<style scoped>

</style>
